module.exports = (app) => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;

  const GroupfriendsSchema = new Schema(
    {
      ownerWxid: { type: String, required: true, index: true }, // 所属微信号
      typename: { type: String, default: "群友"  },
      phone: { type: String, default: '' },
      submitnum: { type: Number, default: 0 },
      content: { type: String, default: "" },
      country: { type: String, default: "" },
      province: { type: String, default: "" },
      city: { type: String, default: "" },
      v3: { type: String, default: "" },
      v4: { type: String, default: "" },
      nick: { type: String, default: "" },
      sex: { type: String, default: "" },
      avatarMinUrl: { type: String, default: "" },
      avatarMaxUrl: { type: String, default: "" },
      friendwxid: { type: String, default: "" },
      groupwxid: { type: String, default: "" },
      triggerTime: { type: Date }, // 打招呼触发时间
      logs: [
        {
          wxid: { type: String },
          nick: { type: String },
          content: { type: String }, // 打招呼文本
          msg: { type: String },
          timeStamp: { type: String },
        },
      ],
      istask: { type: Boolean, default: false },
      isok: { type: Boolean, default: false },
      isfriend: { type: Boolean, default: false },
    },
    {
      timestamps: { createdAt: "createTime", updatedAt: "updateTime" },
    }
  );

  // 索引建议（提高查询效率）
  GroupfriendsSchema.index({ istask: 1 });
  GroupfriendsSchema.index({ triggerTime: 1 });
  GroupfriendsSchema.index({ isok: 1 });

  return mongoose.model("Groupfriends", GroupfriendsSchema, "Groupfriends");
};
